package com.caojin.util;

import java.io.File;

/**
 * 文件处理工具类
 * @author caojin
 *
 */
public class FileUtil {
	public final static String FILE_NOT_FOUND = new String();

	private FileUtil() {
		throw new UnsupportedOperationException();
	}

	/**
	 * 在指定目录下查找指定文件
	 * @param parentPath
	 * @param fileName
	 * @return
	 */
	public static String getAbsolutePath(String parentPath, String fileName) {
		File f = new File(parentPath);
		File[] files = f.listFiles();
		if (files == null) {
			return FILE_NOT_FOUND;
		}
		String filePath = FILE_NOT_FOUND;
		for (File file : files) {
			if (file.isDirectory()) {
				String temp = null;
				if ((temp = getAbsolutePath(file.getAbsolutePath(), fileName)) != FILE_NOT_FOUND) {
					filePath = temp;
				}
			} else if (file.getName().equals(fileName)) {
				filePath = file.getAbsolutePath();
				break;
			}
		}
		return filePath;
	}
}
